/**
 * @Author: easten
 * @Created: 2024-07-21 17:44:51
 * @Description: 终端管理接口
 *
 */
import { IotTerminal } from "_common/entity";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";

export class ApiTerminal {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/iot/terminal/";

  /**
   * @description 构造函数
   * @param config axios 配置
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }

  /** 创建终端 */
  createTerminal(data: IotTerminal) {
    return this.request.post<boolean>(this.url + "", data);
  }

  /** 更新终端 */
  updateTerminal(data: IotTerminal) {
    return this.request.put<boolean>(this.url + "", data);
  }

  /** 删除终端 */
  deleteTerminal(id: number) {
    return this.request.delete<boolean>(this.url + "" + id);
  }

  /** 获取终端信息 */
  getTerminalInfo(id: number) {
    return this.request.get<IotTerminal>(this.url + "get-attr", { id });
  }

  /** 获取终端列表 */
  getTerminalList() {
    return this.request.get<IotTerminal[]>(this.url + "get-list");
  }

  // 获取终端结构树
  getTerminalTree() {
    return this.request.get<any[]>(this.url + "get-tree");
  }

  // 获取终端分页列表
  getPageList(params: any) {
    return this.request.get<any>(this.url + "get-page", params);
  }
}
